package com.sbtr.business.classify.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.sbtr.business.classify.entity.AlgoTemplateParam;
import com.sbtr.business.classify.dto.AlgoTemplateParamDto;

import com.sbtr.business.classify.service.AlgoTemplateParamService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sbtr.business.classify.mapper.AlgoTemplateParamMapper;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sbtr.common.PageDto;
import com.sbtr.util.PageDtoUtils;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * 轻量化算法模板参数(高质量芯片项目)，属于参数版本子表 Service接口实现类
 *
 * @author maojianping
 * @since  2023-04-17
 */
@Transactional
@Service
public class AlgoTemplateParamServiceImpl extends ServiceImpl<AlgoTemplateParamMapper,AlgoTemplateParam> implements AlgoTemplateParamService {

 /*   @Autowired
    AlgoTemplateParamMapper algoTemplateParamMapper;
*/
    @Override
    public PageDto<AlgoTemplateParam> pageList(AlgoTemplateParamDto algoTemplateParamDto) {

        IPage<AlgoTemplateParam> page = new Page<>();
        page.setSize(algoTemplateParamDto.getPageSize());
        page.setCurrent(algoTemplateParamDto.getPage());
        page = baseMapper.selectPages(page, BeanUtil.beanToMap(algoTemplateParamDto));
        PageDto<AlgoTemplateParam> r = PageDtoUtils.getPageDtoByIPage(page, AlgoTemplateParam.class);

        return r;
    }

    @Override
    public List<AlgoTemplateParam> queryList(Long paramVersionId) {
        List<AlgoTemplateParam> paramList = baseMapper.queryList(paramVersionId);
        return paramList;
    }

    @Override
    public boolean delByVersionId(Serializable paramVersionId) {
        // 删除与训练服务器的关联关系
        QueryWrapper<AlgoTemplateParam> wrapper = new QueryWrapper<>();
        wrapper.eq("param_version_id", paramVersionId);
        return this.remove(wrapper);
    }


}

